﻿package com.urbansquall.ui
{

import flash.text.*;

public class CustomTextField extends TextField
{
		
	public function CustomTextField( a_text: String = "", a_color: uint = 0x000000, a_size: int = 28, a_font:String = "Arial", a_embed:Boolean=false )
	{
		this.autoSize = TextFieldAutoSize.LEFT;
		this.selectable = false;
		this.embedFonts = a_embed;
		this.defaultTextFormat = new TextFormat( a_font, a_size, a_color, null, null, null, null, null, TextFormatAlign.RIGHT );
		this.text = a_text;
	}
	
	public function center(): void
	{
		var f: TextFormat = copyTextFormat();
		f.align = TextFormatAlign.CENTER;
		this.defaultTextFormat = f;
	}
	
	public function rightAlign(): void
	{
		var f: TextFormat = copyTextFormat();
		f.align = TextFormatAlign.RIGHT;
		this.defaultTextFormat = f;
	}
	
	public function set size( a_size: int ): void
	{
		var f: TextFormat = copyTextFormat();
		f.size = a_size;
		this.defaultTextFormat = f;
	}
	
	public function set leading( a_val: int ): void
	{
		var f: TextFormat = copyTextFormat();
		f.leading = a_val;
		this.defaultTextFormat = f;
	}
	
	public function underline(): void
	{
		var f: TextFormat = copyTextFormat();
		f.underline = true;
		this.defaultTextFormat = f;
	}
	
	private function copyTextFormat(): TextFormat
	{
		var f: TextFormat = this.defaultTextFormat;
		f = new TextFormat( f.font, f.size, f.color, f.bold, f.italic, f.underline,
			f.url, f.target, f.align, f.leftMargin, f.rightMargin, f.indent, f.leading );
		return f;
	}
}
	
}